﻿using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Configuration;

using MySql.Data.MySqlClient;
using Think.Lenovo.Com.Models;
using Think.Lenovo.Com.Common;
using Think.Lenovo.Com.Models.Questionnaire;

namespace Think.Lenovo.Com.DataAccess.Questionnaire
{
    public class DiaoChaWenJuan
    {
        public DataSet  GetDiaoChaWenJuan(int pageIndex,int pageSize,String conditions,String orderBy)
        {
            String conn = ConfigurationManager.ConnectionStrings["MySqlHost"].ConnectionString;
            DataSet ds = new DataSet();
            StringBuilder sql = new StringBuilder();
            sql.Append("Select * From survey ");
            if (!String.IsNullOrEmpty(conditions))
            {
                sql.Append(" Where " + conditions);
            }
            if (!String.IsNullOrEmpty(orderBy))
            {
                sql.Append(" Order By "+ orderBy+" ");
            }
            sql.Append(" Limit " + (pageIndex - 1) * pageSize + "," +  pageSize);
            ds = MysqlHelper.Query(conn, sql.ToString());
            return ds;
        }
        public int GetDiaoChaWenJuanCount(String condtions)
        {
            String conn = ConfigurationManager.ConnectionStrings["MySqlHost"].ConnectionString;
            StringBuilder sql = new StringBuilder();
            sql.Append("Select Count(Survey_id) From survey ");
            if (!String.IsNullOrEmpty(condtions))
            {
                sql.Append(" Where " + condtions);
            }
            Object obj = MysqlHelper.ExecuteScalar(conn, sql.ToString());
            return obj == null ? 0 : Convert.ToInt32(obj);
        }
    }
}
